import request from "@/utils/request";
import {ResetPasswordType, SetRolesType, UserQueryVo, UserVo, UserVoPartial} from "@/api/sys/admin/user/types";
import {PATH_SYS_ADMIN} from "@/utils/constant";

const baseUrl = PATH_SYS_ADMIN + '/user/'


/**
 * 查询用户列表
 * @param data
 */
export function getUserListApi(data: PageQuery<UserQueryVo>): PromisePageListType<UserVo> {
    return request.post(baseUrl + 'list', {pageQuery: data})
}

/**
 * 通过用户id获取用户信息
 * @param id
 */
export function getUserByIdApi(id: number): Promise<UserVo> {
    return request.get(baseUrl + id)
}

/**
 * 修改用户
 * @param id
 * @param data
 */
export function editUserApi(id: number, data: UserVoPartial): Promise<any> {
    return request.patch(baseUrl + id, data)

}

/**
 * 添加用户
 * @param data
 */
export function addUserApi(data: UserVoPartial): Promise<any> {
    return request.post(baseUrl, data)

}

/**
 * 修改密码
 * @param data
 */
export function resetPasswordApi(data: ResetPasswordType): Promise<any> {
    return request.patch(baseUrl + 'reset-password', data)
}

/**
 * 删除用户
 * @param id
 */
export function deleteUserApi(id: number): Promise<any> {
    return request.delete(baseUrl + id)
}

/**
 * 设置角色
 * @param data
 */
export function setRoleIdsApi(data: SetRolesType) {
    return request.post(baseUrl + 'set-roles', data)
}

/**
 * 批量删除用户
 */
export function batchDeleteUserApi(data: number[]) {
    return request.post(baseUrl + 'batch-delete', {ids: data})
}